package com.xxx;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Servlet
 */
@WebServlet("/aa")
public class Servlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Servlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//常用的request，response方法
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		String name=request.getParameter("name");//获取请求参数,页面nane
		//路径大杂烩
		
		String path=request.getServletPath();
		StringBuffer path1=request.getRequestURL();//URL统一资源定位符
		String path4=path1.toString();
		String path3=request.getSession().getServletContext().getRealPath("");
		String path2=request.getRequestURI();//URI统一资源标识符
		System.out.println(path);
		System.out.println(path2);
		System.out.println(path3);
		System.out.println(path4);
		request.setAttribute("name", name);//第一个name作用域建的对象名称叫name
		response.sendRedirect("NewFile1.jsp");//重定向没有获取到作用域里面的参数
		//request.getRequestDispatcher("NewFile1.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
